package com.ruoyi.user.service.impl;

import com.ruoyi.system.domain.SpffVideos;
import com.ruoyi.system.mapper.SpffVideosMapper;
import com.ruoyi.user.service.IVideoSearchService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.*;

/**
 * 视频搜索Service业务层处理
 * 
 * @author xjj
 * @date 2025-01-28
 */
@Service
public class VideoSearchServiceImpl implements IVideoSearchService 
{
    @Autowired
    private SpffVideosMapper spffVideosMapper;

    /**
     * 搜索视频
     */
    @Override
    public List<SpffVideos> searchVideos(String keyword, Long categoryId, String tags, 
                                        Long userId, String location, String sortBy, 
                                        Integer pageNum, Integer pageSize)
    {
        // 构建搜索参数
        Map<String, Object> params = new HashMap<>();
        params.put("keyword", keyword);
        params.put("categoryId", categoryId);
        params.put("sortBy", sortBy != null ? sortBy : "hot");
        params.put("offset", (pageNum - 1) * pageSize);
        params.put("limit", pageSize);

        // 查询数据库
        List<SpffVideos> result = spffVideosMapper.searchVideos(params);
        return result != null ? result : new ArrayList<>();
    }
}